<?php

/**
 * @author     Thibaut Cromphaut and Dimitry Dierickx
 * @copyright  Copyright (c) 2011 Safti-Kado
 */
class IndexController extends Zend_Controller_Action
{

    public function init()
    {
        $this->stylesBase = $this->view->baseUrl() . '/styles/';
    }

    public function preDispatch()
    {
        // Als de gebruiker geen identiteit heeft, ga naar loginController indexAction.
        if (!Zend_Auth::getInstance()->hasIdentity()) {
             $this->_helper->redirector('index', 'user'); // Zend_Controller_Action_Helper_Redirector
        }   
    }

    public function indexAction()
    {        
        $storage = Zend_Auth::getInstance()->getStorage()->read();

        $view = $this->_getView('Home');
        $view->user = "{$storage->user_givenname} {$storage->user_familyname}";

    }
    
 
    /**
     * @param string $title
     * @return Zend_View
     */
    private function _getView($title)
    {
        $view = $this->view;
        $view->title = $title;
        $view->headTitle($view->title, 'prepend');                           // Zend_View_Helper_HeadTitle
        $view->headLink()->appendStylesheet($this->stylesBase . 'main.css'); // Zend_View_Helper_HeadLink

        return $view;
    }
}
